//
//  NewFriendViewController.m
//  BaChat
//
//  Created by 刘洋 on 16/6/14.
//  Copyright © 2016年 刘洋. All rights reserved.
//

#import "NewFriendViewController.h"
#import "NewFriendModel.h"
#import "FriendTableViewCell.h"

static NSString *FriendNewCell = @"newFriendCell";

@interface NewFriendViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,retain)NSMutableArray *friendNewList;
@property(nonatomic,retain)NSMutableDictionary *friendNewDic;
@property(nonatomic,retain)BaseTableView *friendNewTableView;

@end

@implementation NewFriendViewController

-(void)dealloc{
    [_friendNewDic release];
    [_friendNewList release];
    [_friendNewTableView release];
    [super dealloc];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    
    NSMutableDictionary *dic = [AppDelegate shareFriendDic];
    
    for (NSString *keyString in dic) {
        NewFriendModel *model = [[NewFriendModel alloc]init];
        model.name = keyString;
        model.message = [dic objectForKey:keyString];
        [self.friendNewList addObject:model];
        [model release];
        
    }
    
    
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.friendNewList = [NSMutableArray array];
    NSLog(@"%@",self.friendNewList);
//    [[EaseMob sharedInstance].chatManager addDelegate:self delegateQueue:nil];
    
    self.navigationItem.title = @"新朋友";
    
     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"navigationbar_back_light"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(leftAction)];
    
    
    self.friendNewTableView = [[BaseTableView alloc]initWithFrame:CGRectMake(0, 0, ROOTWIDTH, ROOTHEIGHT - naVCHeight) style:UITableViewStylePlain];
    self.friendNewTableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.friendNewTableView];
    [_friendNewTableView release];
    
    self.friendNewTableView.delegate = self;
    self.friendNewTableView.dataSource = self;
    
    self.friendNewTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.friendNewTableView registerClass:[FriendTableViewCell class] forCellReuseIdentifier:FriendNewCell];
    
    
    
    // Do any additional setup after loading the view.
}

-(void)leftAction{
    [self.navigationController popViewControllerAnimated:YES];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return self.friendNewList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    FriendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FriendNewCell];
    NewFriendModel *model = self.friendNewList[indexPath.row];
    cell.friendModel = model;
    return cell;
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
    
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
